package com.byzk.p2p.admin.admin.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzk.p2p.admin.admin.dao.AdminDao;
import com.byzk.p2p.admin.admin.dto.SysUser;
import com.byzk.p2p.admin.admin.vo.AdminUserVo;
import com.byzk.p2p.admin.base.util.PageInfo;

@Service
public class AdminService {
	
	@Autowired
	private AdminDao adminDao;
	
	/**
	 * 查询系统用户
	 * @param queryMap
	 * @param index
	 * @param limit
	 * @return
	 */
	public PageInfo<AdminUserVo> adminUserList(Map<String, Object> queryMap,Integer index,Integer limit){
		if (index != null && limit != null) {
			if (queryMap == null) {
				queryMap = new HashMap<String, Object>();
			}
			queryMap.put("start", (index-1)*limit);
			queryMap.put("limit", limit);
		}
		Integer total = adminDao.count(queryMap);
		List<AdminUserVo> list = adminDao.list(queryMap);
		PageInfo<AdminUserVo> pageInfo = new PageInfo<AdminUserVo>(total, index, limit);
		pageInfo.setPageList(list);
		return pageInfo;
	}
	
	/**
	 * 根据系统用户id获取系统用户
	 * @param id 系统用户id
	 * @return
	 */
	public SysUser getSysUsersById(Integer id){
		return adminDao.getAdminUserById(id);
	} 
	
	/**
	 * 保存系统用户
	 * @param sysUser 系统用户
	 * @return
	 */
	public Integer saveOrUpdate(SysUser sysUser){
		if (sysUser.getId() == null) {
			return adminDao.insert(sysUser);
		}else{
			return adminDao.update(sysUser);
		}
	}
	
	public SysUser getByName(String name){
		return adminDao.getByName(name);
	}
	
	public SysUser getByPassword(String password){
		return adminDao.getByPassword(password);
	}
	
	public AdminUserVo getVoByName(String name){
		return adminDao.getVoByName(name);
	}

	public AdminDao getAdminDao() {
		return adminDao;
	}
}
